package com.neusoft.service.impl;

import java.security.KeyPair;
import java.security.PublicKey;

import javax.annotation.PostConstruct;
import javax.crypto.SecretKey;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.neusoft.mapper.UserMapper;
import com.neusoft.po.User;
import com.neusoft.service.UserService;
import com.neusoft.util.Encryption;

@Service
public class UserServiceImpl implements UserService{
	
	@Autowired
	private UserMapper userMapper;

	@Override
	public User getUserByIdByPass(String userId, String password) {
		return userMapper.getUserByIdByPass(userId, password);
	}
	
	@Override
	public int getUserById(String userId) {
		return userMapper.getUserById(userId);
	}
	
	@Override
	public int saveUser(User user) {
		return userMapper.saveUser(user);
	}
	
//	@Autowired
//	private UserMapper userMapper;
//	@Autowired
//	private Encryption encryption;
//	private KeyPair keyPair;
//    private PublicKey publicKey;
//    private SecretKey secretKey;
//    @PostConstruct
//    public void init() {
//        try {
//            keyPair = encryption.generateKeyPair();
//            publicKey = keyPair.getPublic();
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//	@Override
//	public User getUserByIdByPass(String userId, String password) throws Exception{
//		secretKey = encryption.generateAESKey(userId);
//		String encryptedPassword = encryption.encryptWithAES(password,secretKey,publicKey);
//		return userMapper.getUserByIdByPass(userId, encryptedPassword);
//	}
//	
//	@Override
//	public int getUserById(String userId) {
//		return userMapper.getUserById(userId);
//	}
//	
//	@Override
//	public int saveUser(User user) throws Exception{
//		String userId = user.getUserId();
//		String password = user.getPassword();
//		secretKey = encryption.generateAESKey(userId);
//		String encryptedPassword = encryption.encryptWithAES(password,secretKey,publicKey);
//		user.setPassword(encryptedPassword);
//		return userMapper.saveUser(user);
//	}
}
